import java.sql.SQLOutput;

public class BF {
    public static int bf(String str,String sub){
        if(str==null||sub==null){
            return -1;
        }
        int strlen=str.length();
        int sublen=sub.length();
        if(strlen==0||sublen==0){
            return -1;
        }
        int i=0,j=0;
        while (i<strlen&&j<sublen){
            if(str.charAt(i)==sub.charAt(j)){
                i++;
                j++;
            }else {
                i=i-j+1;
                j=0;
            }
        }
        if(j>=sublen){
            return i-j;
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println(bf("aabcda","da"));
    }
}
